// pages/promise/item/item.js
let app = getApp().globalData;
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    item: Object,
  },

  /**
   * 组件的初始数据
   */
  data: {
    showWarn: false,
    entry:"",
    leave:"",
    type:{
      CREATED: ["已创建","grey"],
      ENCLOSURE: ["已入栏","skyblue"],
      FATTENED: ["已出栏","orange"],
      DISPATCHED: ["已分拨","green"],
      Other: ["其他","red"]
    }
  },
  /**
   * 组件的方法列表
   */
  lifetimes: {
    attached() {
      let en = null;
      let lea = null;
      if(this.properties.item.entryTime){
        en = this.properties.item.entryTime.slice(0,10);
        this.setData({
          entry: en.slice(0,4)+"年"+en.slice(5,7)+"月"+en.slice(8,)+'日',
        })
      }
      if(this.properties.item.leaveTime){
        lea = this.properties.item.leaveTime.slice(0,10);
        this.setData({
          leave: lea.slice(0,4)+"年"+lea.slice(5,7)+"月"+lea.slice(8,)+'日',
        })
      }
    }
  },
  pageLifetimes: {
      show(){
          let en = null;
          let lea = null;
          if(this.properties.item.entryTime){
            en = this.properties.item.entryTime.slice(0,10);
            this.setData({
              entry: en.slice(0,4)+"年"+en.slice(5,7)+"月"+en.slice(8,)+'日',
            })
          }
          if(this.properties.item.leaveTime){
            lea = this.properties.item.leaveTime.slice(0,10);
            this.setData({
              leave: lea.slice(0,4)+"年"+lea.slice(5,7)+"月"+lea.slice(8,)+'日',
            })
          }
        }
    },
  methods: {
    open() {
      app.operation = 2;
      app.farm_data = this.properties.item;
      if (!this.properties.isdelete) {
        wx: wx.navigateTo({
          url: "/pages/cultivation/product/product",
          events: false,
          success: (result) => { },
          fail: (res) => { },
          complete: (res) => { },
        });
      }
    },
  },
});
